package kcg;

import static org.junit.Assert.assertTrue;
import kcg.test.RobotTestBed;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.snapshot.IBulletSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that MikeTerry 
 *Firing works. 
 * 
 * @author Philip Johnson Modified for personal use by Kelvin Green
 */
public class TestMikeTerryFiring extends RobotTestBed {
  double startGunHeat = 0;
  double endGunHeat = 0;
  double prevEnergy = 100;

  /**
   * Specifies that SittingDuck and MikeTerry are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,kcg.MikeTerry";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 5;
  }

  /**
   * 
   * 
   * @param event Details about the turn ended.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot sample = event.getTurnSnapshot().getRobots()[0];
    IRobotSnapshot mikeTerry = event.getTurnSnapshot().getRobots()[1];
    double x1 = mikeTerry.getX();
    double y1 = mikeTerry.getY();
    double x2 = sample.getX();
    double y2 = sample.getY();
    if (mikeTerry.getEnergy() < prevEnergy) {
      if (mikeTerry.getEnergy() > sample.getEnergy()) {
        double distance = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
        IBulletSnapshot[] bullet = event.getTurnSnapshot().getBullets();
        double bulletPower = bullet[0].getPower();
        if (distance > 200) {
          assertTrue(bulletPower < 3);
        }
      }
    }
    prevEnergy = mikeTerry.getEnergy();
  }

}
